package num257;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : DuJiabao
 * @Project : sword-finger-offer
 * @Time : 2021/5/9 0:51
 * @Desc :
 */
public class Solution {
  List<String> res = new ArrayList<>();

  public List<String> binaryTreePaths(TreeNode root) {
    recursion(root, "");
    return res;
  }

  public void recursion(TreeNode root, String path) {
    if (root == null) return;
    StringBuilder sb = new StringBuilder(path);
    sb.append(root.val);
    if (root.left == null && root.right == null) {
      res.add(sb.toString());
    }
    sb.append("->");
    recursion(root.left, sb.toString());
    recursion(root.right, sb.toString());
  }

  public static void main(String[] args) {
    TreeNode root = new TreeNode(1);
    root.left = new TreeNode(2);
    root.left.right = new TreeNode(5);
    root.right = new TreeNode(3);
    List<String> res = new Solution().binaryTreePaths(root);
    System.out.println(res);
  }
}
